<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

/**
 * 添加项目环节确认配置表
 */
final class CreateProjectStepCategoryConfirmConfigTable extends AbstractMigration
{
    public function up()
    {
        $this->table('project_step_category_confirm_config', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '项目环节确认配置'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => 'ID'])
            ->addColumn('project_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '项目ID'])
            ->addColumn('step_category_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '环节ID'])
            ->addColumn('confirm_user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '确认用户id'])
            ->addColumn('type', 'enum', ['values' => 'delay,task_work_order,demand_order_confirm', 'default' => 'delay', 'null' => false, 'comment' => '类型'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addIndex(['type', 'project_id', 'step_category_id', 'confirm_user_id'], ['type' => 'unique', 'name' => 'idx_unique_type_project_step_category_user'])
            ->save();
    }

    public function down()
    {
        $this->table('project_step_category_confirm_config')->drop()->save();
    }
}
